package com.googlecode.animator.controller
{
	import com.googlecode.animator.data.IValueObject;
	import com.googlecode.animator.data.cameras.ActualViewCameraVO;
	import com.googlecode.animator.data.objects3d.CameraProxyVO;
	import com.googlecode.animator.data.objects3d.Object3DVO;
	import com.googlecode.animator.data.objects3d.TargetProxyVO;
	
	import org.papervision3d.core.math.Number3D;
	import org.papervision3d.scenes.Scene3D;
	import org.puremvc.as3.interfaces.INotification;

	/**
	 * Responds to whenever a DisplayObject3D involves a mouse up event. 
	 * @author USER
	 * 
	 */
	public class Object3DReleasedCommand extends BaseCommand
	{
		/**
		 * Execute command. 
		 * @param notification
		 * 
		 */
		override public function execute(notification:INotification):void
		{
			
			var scene:Scene3D = settings.scene;

			var pos:Number3D = new Number3D();
			
			pos.x = int(scene.getChildByName(notification.getBody() as String).x);
			pos.y = int(scene.getChildByName(notification.getBody() as String).y);
			pos.z = int(scene.getChildByName(notification.getBody() as String).z);
			
			
			settings.setPosObject3D(notification.getBody() as String, pos);
			
			// must be the selected object
			settings.selectedObject3D = notification.getBody() as String;
			
			var VO:Object3DVO = settings.getObject3D(notification.getBody() as String);
			
			if(VO is CameraProxyVO || VO is TargetProxyVO)
			{
				var cameraPos:Number3D = new Number3D();
				var targetPos:Number3D = new Number3D();
				
				for each(var object3D:Object3DVO in settings.objects3D)
				{
					if(object3D is CameraProxyVO)
					{
						cameraPos.x = object3D.x;
						cameraPos.y = object3D.y;
						cameraPos.z = object3D.z;			
					}
					
					if(object3D is TargetProxyVO)
					{
						targetPos.x = object3D.x;
						targetPos.y = object3D.y;
						targetPos.z = object3D.z;
					}
					
				}
				
				for each(var camera:IValueObject in settings.cameras)
				{
					if(camera as ActualViewCameraVO)
					{
						settings.setPosCamera((camera as ActualViewCameraVO).name, cameraPos, targetPos); 
					}
				}
			}

		}
		
	}
}